<?php
/**
 * @author GhostWei
 * @date Oct 26, 2012
 */
class controller_www_sns extends front_controller_sns {	
	
	public function action_index() {
		$this->view->headDescription = $this->cache()->sns()->getSource()->getTitle() . ',' . $this->language('社区');
		$this->view->tweets = $this->cache()->sns()->getUserTweets(array('limit' => 50));
		$this->render('sns/tweets.phtml');
	}
	
	public function action_user() {
		$uid = $this->_param('uid');
		$this->view->headDescription =$this->_headDescription();
		$this->view->tweets = $this->cache()->sns()->getUserTweets(array('limit' => 50, 'uid' => $uid));
		$title = $this->snsUser ? $this->snsUser->name : $uid;
		$this->_crumbs()->addPage(system_nav_page::create($title)->setRoute('sns/user')->setParams(array('uid' => $uid)));
		$this->render('sns/tweets.phtml');
	}
	
	public function action_topic() {
		$kw = $this->_param('keyword');
		$this->view->headDescription = $kw . ' - ' . $this->cache()->sns()->getSource()->getTitle();
		$this->view->tweets = $this->cache()->sns()->getTopicTweets(array('limit' => 50, 'keyword' => $kw));
		$this->_crumbs()->addPage(system_nav_page::create($kw)->setRoute('sns/topic')->setParams(array('keyword' => $kw)));
		$this->render('sns/tweets.phtml');
	}
	
	protected function _headDescription() {
		$description = '';
		if($this->snsUser) {
			$description .= $this->snsUser->name;
			if($this->snsUser->description) {
				$description .= ' - ' . $this->snsUser->description;
			}
		}
		if($description) {
			$description .= ' - ';
		}
		$description .= $this->cache()->sns()->getSource()->getTitle();
		return $description;
	}
	
}
